﻿<%@ Page Culture="auto" UICulture="auto" Title="Restrictions" Language="C#" MasterPageFile="~/Site.Master"
    AutoEventWireup="true" CodeBehind="Restriction.aspx.cs" Inherits="BM.Tools.WebControls.MForm.Example.Constraints.Restriction" %>

<%@ Register Assembly="BM.Tools.WebControls.MForm" Namespace="BM.Tools.WebControls.MForm.Controls"
    TagPrefix="mf" %>
<%@ Register Assembly="BM.Tools.WebControls.MForm" Namespace="BM.Tools.WebControls.MForm.Controls.Additions"
    TagPrefix="mfadd" %>
<%@ Register TagPrefix="mftitle" Namespace="BM.Tools.WebControls.MForm.Controls.Titles"
    Assembly="BM.Tools.WebControls.MForm" %>
<asp:Content ContentPlaceHolderID="Demonstration" runat="server">
    <p>
        In the following demonstration each of the restriction types is presented.
    </p>
    <mf:RootValidator runat="server" ControlToValidate="Root1" />
    <mf:Root ID="Root1" runat="server">
        <UriMappings>
            <mf:UriMapping Prefix="xs" Namespace="http://www.w3.org/2001/XMLSchema" />
            <mf:UriMapping Prefix="" Namespace="" />
        </UriMappings>
        <Contents>
            <mf:Branch Name="ValidationExample" runat="server">
                <Contents>
                    <div class="MForm-Title SubTitle">
                        <div class="MForm-Content">
                            Pattern example - provide email
                        </div>
                    </div>
                    <mf:Leaf Name="Email" runat="server">
                        <Additions>
                            <mfadd:Restriction runat="server" ErrorText="Email wrong" RestrictionType="Pattern"
                                Value="([\.a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(([a-zA-Z0-9_-])*\.([a-zA-Z0-9_-])+)+" />
                        </Additions>
                    </mf:Leaf>
                    <div class="MForm-Title SubTitle">
                        <div class="MForm-Content">
                            Length example - provide exactly 10 characters
                        </div>
                    </div>
                    <mf:Leaf Name="Exactly10Characters" runat="server">
                        <Additions>
                            <mfadd:Restriction runat="server" RestrictionType="Length" Value="10" />
                        </Additions>
                    </mf:Leaf>
                    <div class="MForm-Title SubTitle">
                        <div class="MForm-Content">
                            MinLength example - provide 3 characters or more
                        </div>
                    </div>
                    <mf:Leaf Name="MinLengthOf3" runat="server">
                        <Additions>
                            <mfadd:Restriction runat="server" RestrictionType="MinLength" Value="3" />
                        </Additions>
                    </mf:Leaf>
                    <div class="MForm-Title SubTitle">
                        <div class="MForm-Content">
                            MaxLength example - provide 7 characters or less
                        </div>
                    </div>
                    <mf:Leaf Name="MaxLengthOf7" runat="server">
                        <Additions>
                            <mfadd:Restriction runat="server" RestrictionType="MaxLength" Value="7" />
                        </Additions>
                    </mf:Leaf>
                    <div class="MForm-Title SubTitle">
                        <div class="MForm-Content">
                            MaxExclusive example - provide a value lower than 100
                        </div>
                    </div>
                    <mf:Leaf Name="LowerThan100" runat="server" DataType="Int">
                        <Additions>
                            <mfadd:Restriction runat="server" RestrictionType="MaxExclusive" Value="100" />
                        </Additions>
                    </mf:Leaf>
                    <div class="MForm-Title SubTitle">
                        <div class="MForm-Content">
                            MaxInclusive example - provide a value lower than or equal 20
                        </div>
                    </div>
                    <mf:Leaf Name="LowerOrEqual20" runat="server" DataType="Int">
                        <Additions>
                            <mfadd:Restriction runat="server" RestrictionType="MaxInclusive" Value="20" />
                        </Additions>
                    </mf:Leaf>
                    <div class="MForm-Title SubTitle">
                        <div class="MForm-Content">
                            MinExclusive example - provide a value higher than 40
                        </div>
                    </div>
                    <mf:Leaf Name="HigherThan40" runat="server" DataType="Int">
                        <Additions>
                            <mfadd:Restriction runat="server" RestrictionType="MinExclusive" Value="40" />
                        </Additions>
                    </mf:Leaf>
                    <div class="MForm-Title SubTitle">
                        <div class="MForm-Content">
                            MinInclusive example - provide a value higher than or equal 10
                        </div>
                    </div>
                    <mf:Leaf Name="HigherOrEqual10" runat="server" DataType="Int">
                        <Additions>
                            <mfadd:Restriction runat="server" RestrictionType="MinInclusive" Value="10" />
                        </Additions>
                    </mf:Leaf>
                    <div class="MForm-Title SubTitle">
                        <div class="MForm-Content">
                            Total digits example - provide a value with no more than 3 digits
                        </div>
                    </div>
                    <mf:Leaf Name="Leaf1" runat="server" DataType="Decimal">
                        <Additions>
                            <mfadd:Restriction ID="ThreeDigits" runat="server" RestrictionType="TotalDigits"
                                Value="3" />
                        </Additions>
                    </mf:Leaf>
                    <div class="MForm-Title SubTitle">
                        <div class="MForm-Content">
                            Fraction digits example - provide a value with no more than 2 fraction digits
                        </div>
                    </div>
                    <mf:Leaf Name="Leaf2" runat="server" DataType="Decimal">
                        <Additions>
                            <mfadd:Restriction ID="TwoFractionDigits" runat="server" RestrictionType="FractionDigits"
                                Value="2" />
                        </Additions>
                    </mf:Leaf>
                </Contents>
            </mf:Branch>
        </Contents>
    </mf:Root>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="Description" runat="server">
    <p>
        The aim of the restriction constraint is to port all the data type restrictions
        from xsd to the MForm control.
    </p>
    <p>
        When generating the form from the schema, the restrictions will appear in the <code>
            Additions</code> property of the corresponding item.
    </p>
    <p>
        The <code>Restriction</code> control has two important properties:</p>
    <ul>
        <li><code>RestrictionType</code> - the restriction type</li>
        <li><code>Value</code> - the value that the restriction will consume</li>
    </ul>
    <p>
        There are several constraint types, most of them corresponding to the xml schema
        restriction types:</p>
    <ul>
        <li><code>MaxLength</code> - the maximal field length</li>
        <li><code>MinLength</code> - the minimal field length</li>
        <li><code>Length</code> - the exact field length</li>
        <li><code>MinInclusive</code> - the field value parsed as number cannot be lower than
            or equal the specified value</li>
        <li><code>MinExclusive</code> - the field value parsed as number cannot be lower than
            the specified value</li>
        <li><code>MaxInclusive</code> - the field value parsed as number cannot be higher than
            or equal the specified value</li>
        <li><code>MaxExclusive</code> - the field value parsed as number cannot be higher than
            the specified value</li>
        <li><code>Pattern</code> - the field value must match the specified pattern (the pattern
            should be written in the <code>Value</code> property)</li>
        <li><code>TotalDigits</code> - the field value parsed as number cannot have more total
            number of digits than the specified value</li>
        <li><code>FractionDigits</code> - the field value parsed as number cannot have more
            fraction digits than the specified value</li>
    </ul>
</asp:Content>
